package com.bc004346.travelus.fragment;

import android.app.Activity;
import android.app.ListFragment;
import android.widget.ArrayAdapter;

import com.bc004346.travelus.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Renats on 5/31/2014.
 * Travel Alert fragment
 */
public class NoticesFragment extends ListFragment {

    private Activity mActivity;

    public Activity getParentActivity() {
        if (mActivity == null)
            mActivity = getActivity();
        return mActivity;
    }

    public void Populate(List<String> notices) {

        if (notices.size() > 0) {
            List<String> list = new ArrayList<String>();
            for (String pax : notices)
                list.add(pax);
            ArrayAdapter<String> flightArrayAdapter =
                    new ArrayAdapter<String>(getParentActivity(),
                            R.layout.list_notices, list);
            setListAdapter(flightArrayAdapter);
        } else {
            ArrayAdapter<String> flightArrayAdapter =
                    new ArrayAdapter<String>(getParentActivity(),
                            R.layout.list_notices, new ArrayList<String>() {{
                        add(mActivity.getString(R.string.common_no_active_notices));
                    }}
                    );
            setListAdapter(flightArrayAdapter);

        }
    }
}
